# The purpose of this pipeline is to run the trimming tests. These tests ensure trimming is
# done correctly and also that our APIs are trimming safe.

trigger:
  batch: true
  branches:
    include:
    - release/*.*
  paths:
    include:
    - '*'
    exclude:
    - '**.md'
    - eng/Version.Details.xml
    - .devcontainer/*
    - .github/*
    - docs/*
    - LICENSE.TXT
    - PATENTS.TXT
    - THIRD-PARTY-NOTICES.TXT
    - eng/pipelines/coreclr/perf*yml
    - eng/pipelines/coreclr/templates/build-perf*
    - eng/pipelines/coreclr/templates/perf-job.yml
    - eng/pipelines/coreclr/templates/run-perf*
    - eng/testing/performance/*

schedules:
  - cron: "0 7,19 * * *" # run at 7:00 and 19:00 (UTC) which is 23:00 and 11:00 (PST).
    displayName: Runtime-linker-tests default schedule
    branches:
      include:
      - main
    always: false # run only if there were changes since the last successful scheduled run.

pr:
  branches:
    include:
    - main
    - release/*.*
  paths:
    include:
    - '*'
    exclude:
    - '**.md'
    - eng/Version.Details.xml
    - .devcontainer/*
    - .github/*
    - docs/*
    - LICENSE.TXT
    - PATENTS.TXT
    - THIRD-PARTY-NOTICES.TXT

variables:
  - template: /eng/pipelines/common/variables.yml

extends:
  template:  /eng/pipelines/common/templates/pipeline-with-resources.yml
  parameters:
    stages:
    - ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
      - stage: EvaluatePaths
        displayName: Evaluate Paths
        jobs:
          - template: /eng/pipelines/common/evaluate-default-paths.yml

    - stage: Build
      jobs:
      #
      # Build and Test ILLink in Release config vertical for Windows, Linux and OSX
      #
      - template: /eng/pipelines/common/platform-matrix.yml
        parameters:
          jobTemplate: /eng/pipelines/common/global-build-job.yml
          buildConfig: release
          platforms:
          - windows_x64
          - osx_x64
          - linux_x64
          jobParameters:
            testGroup: innerloop
            enablePublishTestResults: true
            timeoutInMinutes: 120
            nameSuffix: ILLink_Runtime_Testing
            condition:
              or(
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_tools_illink.containsChange'], true),
                eq(variables['isRollingBuild'], true))
            buildArgs: -s tools.illinktests -test -c $(_BuildConfig)

      #
      # Build Release config vertical for Windows, Linux, and OSX
      #
      - template: /eng/pipelines/common/platform-matrix.yml
        parameters:
          jobTemplate: /eng/pipelines/common/global-build-job.yml
          buildConfig: release
          platforms:
          - windows_x64
          - osx_x64
          - linux_x64
          jobParameters:
            testGroup: innerloop
            timeoutInMinutes: 120
            nameSuffix: Runtime_Release
            condition:
              or(
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_non_mono_and_wasm.containsChange'], true),
                eq(variables['isRollingBuild'], true))
            buildArgs: -s clr+libs+tools.illink -c $(_BuildConfig)
            postBuildSteps:
              - template: /eng/pipelines/libraries/execute-trimming-tests-steps.yml

      #
      # Build Release config vertical for Browser-wasm
      #
      - template: /eng/pipelines/common/platform-matrix.yml
        parameters:
          jobTemplate: /eng/pipelines/common/global-build-job.yml
          buildConfig: release
          platforms:
          - browser_wasm
          jobParameters:
            testGroup: innerloop
            timeoutInMinutes: 120
            nameSuffix: Runtime_Release
            buildArgs: -s mono+libs+tools.illink -c $(_BuildConfig) -p:WasmBuildNative=false -p:AotHostArchitecture=x64 -p:AotHostOS=$(_hostedOS)
            condition:
              or(
                eq(variables['isRollingBuild'], true),
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_libraries.containsChange'], true),
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_wasm_specific_except_wbt_dbg.containsChange'], true),
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_tools_illink.containsChange'], true),
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['DarcDependenciesChanged.Microsoft_NET_ILLink_Tasks'], true))
            postBuildSteps:
              - template: /eng/pipelines/libraries/execute-trimming-tests-steps.yml
                parameters:
                    extraTestArgs: '/p:WasmBuildNative=false'
